home *** CD-ROM | disk | FTP | other *** search
- Path: news.itsnet.com!usenet
- From: Jonathan Ord <jord@itsnet.com>
- Newsgroups: comp.lang.c++
- Subject: PLEASE HELP ME FINISH A TUTORIAL I AM STUCK. THANKS
- Date: Sun, 24 Mar 1996 20:23:37 -0800
- Organization: Internet Technology Systems, Provo UT USA
- Message-ID: <31561FC9.77DA@itsnet.com>
- NNTP-Posting-Host: ip211.itsnet.com
- Mime-Version: 1.0
- Content-Type: multipart/mixed; boundary="------------29E172193294"
- X-Mailer: Mozilla 2.0 (Win95; I)
-
- This is a multi-part message in MIME format.
-
- --------------29E172193294
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
-
- I am just starting out and having some trouble. I am trying to learn
- this out of a book. I have started by trying to complete an assignment
- using linked lists and functions. I continue to get errors and can't
- figure out how to delete a record from a specified record in the lists
- that I create.
-
- This is the criteria for the excercise.
-
- Your program must display the following menu:
- 1. Add a stamp to the list
- 2. Display all the stamps in your list
- 3. Display the least expensive stamp in the list
- 4. Display the most expensive stamp in the list
- 5. Remove a particular stamp from the list
- 6. Exit the program
-
- After displaying the menu, ask the user to enter a choice, then perform
- the requested action and repeat this process until the user chooses to
- exit.
- Design an appropriate sturcture to capture 3 properties of stamp
- collection. Store the stamps in a linked list. (using C++ new and
- delete operators to allocate and deallocate storage for the stamp
- structures.
- Be sure that all of the structures work whether the list is empty or
- not. Redisplay the menu if a choice is not valid.
- For item 5, I have to devise a way for the user to indicate which stamp
- is to be deleted. Two possibilities include asking the user for a
- description of the stam to delete or showing the user each stamp and
- asking him or her to say whether this is the one to delete.
-
- Anyone that can help me please feel free to look at my program and make
- changes and comments and e-mail it back to me @jord@itsnet.com .
-
- I would like to receive some feedback tonight if possible. Thank you in
- advance for the help.
- --
-
- --------------29E172193294
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- Content-Disposition: inline; filename="Exam_2.cpp"
-
- /* Jonathan Ord
- ISYS 440 Exam #2
- Dr. Little
- March 23, 1996
- Description ==The program will let me keep track of rare stamps through the
- use of the functions associated with the following menu:
- 1. Add stamp to list
- 2. Display all the stamps in the list
- 3. Display the least expensive stamp in the list
- 4. Display the most expensive stamp in the list
- 5. Remove a particular stamp from the list
- 6. Exit the program
- */
- //------------------------------------------------------------------------------
- //INCLUDES
-
- #include <iostream.h>
- #include <string.h>
-
- //------------------------------------------------------------------------------
- //VARIABLES
-
- struct STAMP {
- char *name;
- long price;
- int mint_number;
- STAMP *next;
- };
-
- const int MAX_STRING_LEN = 128;
-
- //==============================================================================
- //FUNCTIONS
- //------------------------------------------------------------------------------
- //Enter stamp data function
-
- void
- Enter_Stamp_Data(STAMP *stp)
- {
- char temp_string[MAX_STRING_LEN];
-
- cout << "ENTER THE STAMP NAME: ";
- cin.get(temp_string, MAX_STRING_LEN);
- stp->name = new char [strlen(temp_string) + 1];
- strcpy(stp->name, temp_string);
- cout << "ENTER THE STAMP'S PRICE IN PESETAS: ";
- cin >> stp->price;
- cout << "ENTER THE STAMP'S MINT NUMBER: ";
- cin >> stp->mint_number;
- }
-
- //------------------------------------------------------------------------------
- //Append stamp to end of linked list or end of previous node function
-
- void
- Append_Stamp_Node(STAMP * &first, STAMP *stp_ptr)
- {
- if (first == NULL)
- first = stp_ptr;
- else {
- STAMP *current = first;
-
- while (current->next != NULL)
- current = current->next;
- current->next = stp_ptr;
- }
- }
-
- //------------------------------------------------------------------------------
- //Display all of the stamps in the list function
-
- void
- Display_Stamp_Data(STAMP * &head, STAMP *stp_ptr)
- {
- for (stp_ptr = head; stp_ptr != NULL; stp_ptr = stp_ptr->next)
- cout << stp_ptr->name << endl;
- cout << stp_ptr->price << endl;
- cout << stp_ptr->mint_number << endl;
- cout << endl;
- }
-
- //------------------------------------------------------------------------------
- //Find most expensive stamp in list function
-
- void
- Find_Highest_Stamp(STAMP * &head, STAMP *stp_ptr)
- {
- long highest_price = 0;
- char name;
-
- for (stp_ptr = head; stp_ptr != NULL; stp_ptr = stp_ptr->next) {
- if (stp_ptr->price > highest_price) {
- highest_price = stp_ptr->price;
- name = stp_ptr->name;
- }
- }
- cout << "THE MOST EXPENSIVE STAMP IN THE LIST IS: " << name << endl;
- cout << "THE COST OF " << name << "IS " << highest_price << endl;
- }
- //------------------------------------------------------------------------------
- //Find least expensive stamp in list function
-
- void
- Find_Lowest_Stamp(STAMP * &head, STAMP *stp_ptr)
- {
- long lowest_price = 2,147,483,647;
- char name;
-
- for (stp_ptr = head; stp_ptr != NULL; stp_ptr = stp_ptr->next) {
- if (stp_ptr->price < lowest_price) {
- lowest_price = stp_ptr->price;
- name = stp_ptr->name;
- }
- }
- cout << "THE LEAST EXPENSIVE STAMP IN THE LIST IS: " << name << endl;
- cout << "THE COST OF " << name << "IS " << lowest_price << endl;
- }
- //------------------------------------------------------------------------------
- //Delete a choosen record from the list function
-
- void
- Delete_Stamp_Data(STAMP * &head, STAMP *stp_ptr)
- {
- int answer;
-
- for (stp_ptr = head; stp_ptr != NULL; stp_ptr = stp_ptr->next)
- cout << stp_ptr->name << endl;
- cout << stp_ptr->price << endl;
- cout << stp_ptr->mint_number << endl;
- cout << endl;
- cout << "DO YOU WANT TO DELETE THIS RECORD? (Y FOR YES, N FOR NO) " << endl;
- cin >> answer >> endl;
- if (answer == 'y') {
- }}
-
- //==============================================================================
- //Main Program - references above functions to accomplish stamp assignment
-
- void
- main()
- {
- STAMP *head = NULL,
- *stp_ptr;
- int answer;
-
- cout << "CHOOSE ONE (1-6) OF THE FOLLOWING MENU OPTIONS:" << endl;
- cout << "1 -- ADD A NEW STAMP RECORD" << endl;
- cout << "2 -- DISPLAY ALL THE STAMPS IN THE LIST" << endl;
- cout << "3 -- DISPLAY THE MOST EXPENSIVE STAMP IN THE LIST" << endl;
- cout << "4 -- DISPLAY THE LEAST EXPENSIVE STAMP IN THE LIST" << endl;
- cout << "5 -- REMOVE A STAMP FROM THE LIST" << endl;
- cout << "6 -- EXIT THIS PROGRAM" << endl;
-
- cin >> answer >> endl;
-
- switch(answer)
- {
- case 1:
- stp_ptr = new STAMP;
- stp_ptr->next = NULL;
- Enter_Stamp_Data(stp_ptr);
- Append_Stamp_Node(head, stp_ptr;
- break;
- case 2:
-
- break;
- case 3:
-
- break;
- case 4:
-
- break;
- case 5:
-
- break;
- case 6:
-
- break;
-
-
-
-
-
-
- }
-
- --------------29E172193294--
-
-